<?php

include_once "function_admin_manage.php";

$in_array['Name'] = $_POST['Name'];
if ($_POST['PassWord1'] == $_POST['PassWord2'])
	$in_array['PassWord'] = GetCryptText($_POST['PassWord1']);

$in_array['AdminType'] = "";

if ($_POST['Account'] == "1")
	$in_array['AdminType'] .= ACCOUNT . "|";
if ($_POST['Super'] == "1")
	$in_array['AdminType'] .= SUPER . "|";
if ($_POST['Normal'] == "1")
	$in_array['AdminType'] .= NORMAL . "|";
if ($_POST['Design'] == "1")
	$in_array['AdminType'] .= DESIGN . "|";
if ($_POST['Audit'] == "1")
	$in_array['AdminType'] .= AUDIT. "|";

$in_array['Enabled'] = $_POST['enabled'];

$in_array['AdminRange'] = "";

if (($_POST['ip1'] == NULL || $_POST['mask1'] == NULL) || 
    ($_POST['ssh1'] == NULL && $_POST['https1'] ==NULL))
{
	;
}    
else
{    
	if ($_POST['ip1'])
		$in_array['AdminRange'] .= $_POST['ip1'] . "|";
	if ($_POST['mask1'])
		$in_array['AdminRange'] .= $_POST['mask1'] . "%";

	if ($_POST['ssh1'] || $_POST['https1'])
	{
		$in_array['AdminRange'] .= $_POST['ssh1'] . "$";
		$in_array['AdminRange'] .= $_POST['https1'] . "@";
	}
}	

if (($_POST['ip2'] == NULL || $_POST['mask2'] == NULL) || 
    ($_POST['ssh2'] == NULL && $_POST['https2'] ==NULL))
{
	;
}
else
{    
	if ($_POST['ip2'])
		$in_array['AdminRange'] .= $_POST['ip2'] . "|";
	if ($_POST['mask2'])
		$in_array['AdminRange'] .= $_POST['mask2'] . "%";
	if ($_POST['ssh2'] || $_POST['https2'])
	{
		$in_array['AdminRange'] .= $_POST['ssh2'] . "$";
		$in_array['AdminRange'] .= $_POST['https2'];
	}
}

AppendXmlOneSysAdmin($in_array);
ApplyAdminToSystem_Add($in_array["Name"], $in_array["PassWord"],$in_array["Enabled"]);

echo("<meta http-equiv='refresh'content=0;URL='sys_admin_manage.php'>");
?>
